﻿
(function () {
    appModule.controller('common.views.fireFightingWorks.detail', [
        '$scope', '$uibModalInstance', 'abp.services.app.fireFightingWork', 'fireFightingWorkId', 'abp.services.app.area', 'fireFightingWork',
        function ($scope, $uibModalInstance, fireFightingWorkService, fireFightingWorkId, areaService,fireFightingWork) {
            var vm = this;
            vm.saving = false;
            //首先将fireFightingWork数据设置为null
            vm.fireFightingWork = null;

            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //初始化页面
            function init() {
                //绑定镇控件
                areaService.getAreaByLevelAsync({ id: 0 }).then(function (result) {
                    vm.townList = result.data.items;
                });

                //绑定区控件
                areaService.getAreaByLevelAsync({ id: fireFightingWork.townID }).then(function (result) {
                    vm.areaList = result.data.items;
                });
                //绑定村控件
                areaService.getAreaByLevelAsync({ id: fireFightingWork.areaID }).then(function (result) {
                    vm.villageList = result.data.items;
                    
                    fireFightingWorkService.getFireFightingWorkForEditAsync({
                        id: fireFightingWorkId
                    }).then(function (result) {
                        vm.fireFightingWork = result.data.fireFightingWork;
                    });  
                });
            }

            //绑定区
            vm.bindArea = function (townID) {
                areaService.getAreaByLevelAsync({ id: townID }).then(function (result) {
                    vm.areaList = result.data.items;
                });
            };

            //绑定村
            vm.bindVillage = function (areaID) {
                areaService.getAreaByLevelAsync({ id: areaID }).then(function (result) {
                    vm.villageList = result.data.items;
                });
            };

            //执行初始化方法
            init();
        }
    ]);
})();